<?php
class ReadFirstController extends AppController {
	var $name = 'ReadFirst';
	var $uses = array('news.News', 'News.NewsCategory');
	function index($cat_alias = null) {
		if (isset($cat_alias)) {
			$first = $this->News->getFirstRecordInCategory($cat_alias, array('News.alias'));
		} else {
			$firstCat = $this->NewsCategory->find('first', array(
				'contain'	=> array(),
				'fields'	=> array('alias')
			));
			
			$cat_alias = $firstCat['NewsCategory']['alias'];
			$first = $this->News->getFirstRecordInCategory($cat_alias, array('News.alias'));
		}
		
		$this->redirect(array(
			'plugin'		=> 'news',
			'controller'	=> 'news',
			'action'		=> 'view',
			$first['News']['alias'],
			$cat_alias
		));
	}
}